var dateTimePicker = require('../../utils/dateTimePicker.js');

Page({
  data: {
    date: '2018-10-01',
    time: '12:00',
    dateTimeArray: null,
    dateTime: null,
    dateTimeArray1: null,
    dateTime1: null,
    startYear: 2000,
    endYear: 2050,
    dateTimeArray: null,
    dateTime: null,
    dateTimeArray1: null,
    dateTimeArray2: null,
    dateTime1: null,
    dateTime2: null,
    startYear: 2000,
    endYear: 2050
  },
  onLoad() {
    // 获取完整的年月日 时分秒，以及默认显示的数组
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    // 精确到分的处理，将数组的秒去掉
    var lastArray = obj1.dateTimeArray.pop();
    var lastTime = obj1.dateTime.pop();

    this.setData({
      dateTime: obj.dateTime,
      dateTimeArray: obj.dateTimeArray,
      dateTimeArray1: obj1.dateTimeArray,
      dateTimeArray2: obj1.dateTimeArray,
      dateTime1: obj1.dateTime,
      dateTime2: obj1.dateTime
    });
  },
  //   var temp = e.detail.value
  //   var month = temp[1] + 1
  //   var day = temp[2] + 1
  //   var str = '20' + temp[0] + '-' + month + '-' + day + ' ' + temp[3] + ':' + temp[4]
  // changeDateTime1(e) {
  //   this.setData({ dateTime1: e.detail.value });
  // },

  changeDateTimeColumn1(e) {
    var arr = this.data.dateTime1, dateArr = this.data.dateTimeArray1;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    this.setData({
      dateTimeArray1: dateArr,
      dateTime1: arr
    });
  },
  //复制
  changeDateTime2(e) {
    this.setData({ dateTime2: e.detail.value });
  },

  changeDateTimeColumn2(e) {
    var arr = this.data.dateTime2, dateArr = this.data.dateTimeArray2;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    this.setData({
      dateTimeArray2: dateArr,
      dateTime2: arr
    });
  }
})